package com.haliyoo.adhere.activity;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.haliyoo.adhere.R;
import com.haliyoo.adhere.activity.CreativeHallActivity.WeiboList;
import com.haliyoo.adhere.bean.WeiboBean;
import com.haliyoo.adhere.controller.AdUserConstant;
import com.haliyoo.adhere.controller.OAuthConstant;
import com.haliyoo.adhere.util.DateUtilsDef;
import com.haliyoo.adhere.widget.AsyncImageLoader;
import com.haliyoo.adhere.widget.LocalWeiboLayout;
import com.haliyoo.adhere.widget.WeiboLayout;
import com.haliyoo.adhere.widget.AsyncImageLoader.ImageCallback;

import weibo4android.Status;
import weibo4android.User;
import weibo4android.Weibo;
import weibo4android.WeiboException;
import weibo4android.http.AccessToken;
import weibo4android.http.RequestToken;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class InviteFriendsActivity extends Activity {
	private static String TAG = "InviteFriendsActivity";

	/**
	 * 内部类，实现微博数据获取
	 * @author wation.haliyoo
	 *
	 */
	class WeiboList extends LocalWeiboLayout{

		WeiboList(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
		}

		@Override
		public List<WeiboBean> onGetWeiboList() {
			// TODO Auto-generated method stub
			if (LoginActivity.getUser() == null) {
				Toast.makeText(InviteFriendsActivity.this, 
						R.string.STR_NONE_USER, 
						Toast.LENGTH_SHORT).show();
			} else {
				List<WeiboBean> wbList = new ArrayList<WeiboBean>();

				/// 从AdHere服务器下载广告
				AdUserConstant.getInstance().list(AdUserConstant.getInstance().user, 
						AdUserConstant.getInstance().sign);
				
				/// 清空原有list所有项
				wbList.clear();
				
				for (int i=0; i<AdUserConstant.getInstance().inviteList.size(); i++) {
					
					WeiboBean wb = AdUserConstant.getInstance().inviteList.get(i);
					
					wbList.add(wb);
				}
				
				return wbList;
			}
			
			return null;
		}

		@Override
		public void onShowWeiboDetail(AdapterView<?> arg0, View view, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			WeiboBean weiboBean = (WeiboBean) view.getTag();
			if (weiboBean != null) {
				Intent intent = new Intent(InviteFriendsActivity.this,
						CreativeActivity.class);
				Bundle b = new Bundle();
				b.putString("id", weiboBean.getId());
				intent.putExtras(b);
				InviteFriendsActivity.this.startActivity(intent);
			}
		}

		@Override
		public void onShowWeiboDetail(WeiboBean weiboBean) {
			// TODO Auto-generated method stub

			if (weiboBean != null) {
				Intent intent = new Intent(InviteFriendsActivity.this,
						CreativeActivity.class);
				Bundle b = new Bundle();
				b.putString("id", weiboBean.getId());
				intent.putExtras(b);
				InviteFriendsActivity.this.startActivity(intent);
			}
		}

		@Override
		public void onFinishedPublish(WeiboBean weiboBean) {
			// TODO Auto-generated method stub
			
		}
	}

	/// 微博列表
	WeiboList weiboList = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
    	this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.invite_friends);
		
		/// 加载微博列表
		weiboList = new WeiboList(InviteFriendsActivity.this);
		weiboList.refreshWeiboList();
	
		/**
		 * 返回键处理
		 */
		ImageButton ibBack = (ImageButton) findViewById(R.id.IMAGE_BUTTON_BACK);
		ibBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();  
			}
		});

		/**
		 * 刷新键处理
		 */
		ImageButton ibRefresh = (ImageButton) findViewById(R.id.IMAGE_BUTTON_REFRESH);
		ibRefresh.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				/// 加载微博列表
				weiboList.refreshWeiboList();
			}
		});
	}
}
